﻿#define _CRT_SECURE_NO_WARNINGS 1
using namespace std;
#include <deque>
#include <vector>

namespace bit
{
	template <class T,class contain = deque<T>>
	class queue
	{
	public:
	public:
		void push(const T& x)
		{
			_con.push_back(x);
		}

		void pop()
		{
			_con.pop_front();
		}

		const T& front()
		{
			return _con.front();
		}

		const T& back()
		{
			return _con.back();
		}

		size_t size()
		{
			return _con.size();
		}

		bool empty()
		{
			return _con.empty();
		}
	private:
		Container _con;
	};


	template<class T, class Container = vector<T>>
	class priority_queue
	{
	public:
		void adjust_up(int child)
		{
			int parent = (child - 1) / 2;
			while (child > 0)
			{
				if (_con[child] > _con[parent])
				{
					swap(_con[child], _con[parent]);
					child = parent;
					parent = (child - 1) / 2;
				}
				else
				{
					break;
				}
			}
		}

		void adjust_down(int parent)
		{
			int child = parent * 2 + 1;

			while (child < _con.size())
			{
				if (child + 1 < _con.size() && _con[child + 1] > _con[child])
				{
					++child;
				}

				if (_con[child] > _con[parent])
				{
					swap(_con[child], _con[parent]);
					parent = child;
					child = parent * 2 + 1;
				}
				else
				{
					break;
				}
			}
		}

		void push(const T& x)
		{
			_con.push_back(x);

			adjust_up(_con.size() - 1);
		}

		
		void pop()
		{
			swap(_con[0], _con[_con.size() - 1]);
			_con.pop_back();

			adjust_down(0);
		}

		const T& top()
		{
			return _con[0];
		}

		size_t size()
		{
			return _con.size();
		}

		bool empty()
		{
			return _con.empty();
		}
	private:
		Container _con;
	};


	template<class Iterator, class Ref, class Ptr>
	struct Reverse_iterator
	{
		typedef Reverse_iterator<class Iterator, class Ref, class Ptr> Self;

		Iterator cur;

		Reverse_iterator(Iterator it)
			:cur(it)
		{}

		Self& operator++()
		{
			--cur;
			return *this;
		}

		Self operator++(int)
		{
			Self tmp = *this;
			--cur;
			return tmp;
		}

		Self& operator--()
		{
			++cur;
			return *this;
		}

		Self operator--(int)
		{
			Self tmp = *this;
			++cur;
			return tmp;
		}

		Ref operator*()
		{
			Iterator tmp = cur;
			--tmp;
			return *tmp;
		}

		Ptr operator->()
		{
			return &(operator*());
		}

		bool operator!=(const Self& s)
		{
			return cur != s.cur;
		}

		bool operator==(const Self& s)
		{
			return cur == s.cur;
		}
	};
}